package cn.com.inossem.utils.view;

import android.annotation.SuppressLint;
import android.app.DialogFragment;
import android.os.Bundle;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cn.com.inossem.activity.R;

@SuppressLint("NewApi")
public class EditNameDialogFragment extends DialogFragment {

	EditText edit1, edit2;
	int type = 0;

	public EditNameDialogFragment() {
	}

	@SuppressLint("ValidFragment")
	public EditNameDialogFragment(int type) {
		this.type = type;
	}

	public interface LoginInputListener {
		void onLoginInputComplete(String money, String beizhu);
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
	                         Bundle savedInstanceState) {
		getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
		View view = inflater
				.inflate(R.layout.releaseactivity_dialog, container);

		TextView danwei = (TextView) view.findViewById(R.id.danwei);
		if (type == 1)
			danwei.setText("元/月");

		edit1 = (EditText) view.findViewById(R.id.edit1);
		edit1.setSelection(edit1.getText().length());
		edit1.setInputType(InputType.TYPE_CLASS_NUMBER);
		edit2 = (EditText) view.findViewById(R.id.edit2);
		Button button = (Button) view.findViewById(R.id.button);
		button.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				LoginInputListener listener = (LoginInputListener) getActivity();

				listener.onLoginInputComplete(edit1.getText().toString(), edit2
						.getText().toString());
			}
		});

		return view;
	}
}
